package com.niit.galuser.service.impl;

import com.niit.dao.CollectDao;
import com.niit.dao.GameDao;
import com.niit.dao.UpvoteDao;
import com.niit.entity.Collect;
import com.niit.entity.Game;
import com.niit.entity.Upvote;
import com.niit.galuser.client.GameClient;
import com.niit.galuser.service.VoteService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class VoteServiceImpl implements VoteService {
    @Resource
    private GameClient gameClient;
    @Resource
    private CollectDao collectDao;
    @Resource
    private UpvoteDao upvoteDao;
    @Resource
    private GameDao gameDao;

    @Override
    public List<Game> findvoteGemes(int uid) {
        List<Upvote> upvotes = upvoteDao.queryByUid(uid);
        List<Integer> gids = upvotes.stream().map(Upvote::getGid).collect(Collectors.toList());
        gids.add(0);
//        return gameClient.queryByIds(gids);
        return gameDao.queryByIds(gids);
    }

    @Override
    public List<Game> findCollectGames(int uid) {
        List<Collect> collects = collectDao.queryByUid(uid);
        List<Integer> gids = collects.stream().map(Collect::getGid).collect(Collectors.toList());
        gids.add(0);
        return gameDao.queryByIds(gids);
    }


}
